package com.d3works.apps.base.service;

import com.d3works.apps.base.db.Company;
import com.d3works.apps.base.db.Period;
import com.d3works.exception.D3worksException;
import com.d3works.meta.CallMethod;
import com.google.inject.persist.Transactional;
import java.time.LocalDate;

public interface PeriodService {

  /**
   * Recupère la bonne période pour la date passée en paramètre
   *
   * @param date
   * @param company
   * @return
   * @throws D3worksException
   */
  public Period getActivePeriod(LocalDate date, Company company, int typeSelect)
      throws D3worksException;

  public Period getPeriod(LocalDate date, Company company, int typeSelect);

  public Period getNextPeriod(Period period) throws D3worksException;

  public void testOpenPeriod(Period period) throws D3worksException;

  public void close(Period period) throws D3worksException;

  public void closeTemporarily(Period period) throws D3worksException;

  @Transactional
  public void adjust(Period period);

  /**
   * Check if the period corresponding to the date and the company is closed
   *
   * @param company
   * @param date
   * @throws D3worksException
   */
  public void checkPeriod(Company company, LocalDate date) throws D3worksException;

  /**
   * Check if the periods corresponding to the dates and the company are closed.
   *
   * @param company
   * @param fromDate
   * @param toDate
   */
  public void checkPeriod(Company company, LocalDate fromDate, LocalDate toDate)
      throws D3worksException;

  /**
   * @param period
   * @throws D3worksException if the period is closed
   */
  public void checkPeriod(Period period) throws D3worksException;

  /**
   * @param period
   * @throws D3worksException if the period is permanently or temporally closed
   */
  @CallMethod
  boolean isClosedPeriod(Period period) throws D3worksException;

  public void validateTempClosure(Period period) throws D3worksException;

  public void validateClosure(Period period) throws D3worksException;

  /**
   * Method thats open the period
   *
   * @param period
   */
  void openPeriod(Period period);
}
